<div class="title">
  <div class='content'>
    安装项目
  </div>
  <% if being_edited %>
  <div class='tools'>
    <%= link_to '添加',
          new_install_items_installation_url(@install),
          :remote => true,
          :method => :get,
          :id => :add_install_item
    %>
  </div>
  <% end %>
</div> 
<div class='info'>
  <div id='install_items' class='furnitures'>
    <table cellspacing='1' cellpadding='1'>
      <tr>
        <th rowspan='2'>型号</th>
        <th rowspan='2'>名称</th>
        <th rowspan='2'>材质</th>
        <th rowspan='2'>规格</th>
        <th colspan='3'>件数</th>
        <th rowspan='2'>备注</th>
        <th rowspan='2'>动态</th>
      </tr>
      <tr>
        <th>计划</th>
        <th>完成</th>
        <th>售后</th>
      </tr>
      <% @install.install_items.each do |item| %>      
      <tr id='item_<%= item.id %>' class='order_item <%= cycle '','hh', :name => 'furniture_item' %>'>
        <td><%= item.furniture.furniture_style.code %></td>
        <td><%= item.furniture.furniture_style.name %></td>
        <td><%= item.furniture.material.code %>-<%= item.furniture.material.name %></td>
        <td><%= item.furniture.spec %></td>
        <td class='r'><%= item.has_been_sent_to_installer_count %></td>
        <td class='r'><%= item.installed_count %></td>
        <td class='r'><%= item.after_serviced_count %></td>
        <td title='<%= item.remark %>'><%= truncate item.remark, :length => 20 %></td>
        <td width='80' class='<%= item.status %>'>
          <%= t item.last_feed.code %>  
        </td>
      </tr>
      <tr id='events_<%= item.id %>' class='item_events '>
        <td colspan='9'>
          <table class='events' cellspacing="1" cellpadding="1">
            <tr>
              <th></th>
              <th>描述</th>
              <th>
                <div class='creator'>
                  登记人
                </div>                
                <div id='item_<%= item.id %>_tools' class='item_tools'>                  
                  <% if being_edited %>
                  <div>
                    <%= link_to "修改",
                          edit_install_item_installation_url(item),
                          :remote => true,
                          :method => :get                  
                     %>
                     <%= link_to "删除",
                          destroy_install_item_installation_url(item),
                          :remote => true,
                          :method => :delete,
                          :id => "destroy_item_#{item.id}"    
                     %>
                     <script type="text/javascript" charset="utf-8">
                       $('#destroy_item_<%= item.id %>').bind('ajax:beforeSend', function () {
                         $('#events_<%= item.id %>').hide();
                         $('#item_<%= item.id %>').hide(1000);
                       })
                     </script>
                  </div>    
                  <% end %>                    
                </div>
              </th>                    
            </tr>
            <% item.feeds.each_with_index do |feed,index| %>
            <tr>
              <td width='40px'><%= index + 1 %>.</td>
              <td class='d'>
                <%= raw feed.short_desc %><%= raw feed.remark.present? ? "<br/><b>备注：</b>#{raw(feed.remark) }" : '' %>
              </td>
              <td width='70px'>
                <%= @install.creator.full_name %>
              </td>                    
            </tr>
            <% end %>
            <tr class='<%= cycle '','hh', :name => 'event' %>'>
              <td colspan='7'>
                <% if item.status.has_been_sent_to_installer? %>
                <%= link_to '完成安装',
                      create_installed_installation_url(item),
                      :remote => true,
                      :method => :post,
                      :class => :next_step %>
                <%= link_to '售后服务',
                      edit_after_serviced_installation_url(item),
                      :remote => true,
                      :method => :get,
                      :class => :next_step %>
                <% elsif item.status.has_been_installed? %>
                <%= link_to '取消完成安装',
                      destroy_installed_installation_url(item),
                      :remote => true,
                      :method => :delete,
                      :class => :next_step %>
                <% elsif item.status.after_serviced? %>
                <%= link_to '编辑售后服务',
                      edit_after_serviced_installation_url(item),
                      :remote => true,
                      :method => :get,
                      :class => :next_step %>
                <%= link_to '取消售后服务',
                      destroy_after_serviced_installation_url(item),
                      :remote => true,
                      :method => :delete,
                      :class => :next_step %>
                <% end %>
              </td>
            </tr>
          </table>
        </td>
      </tr>    
      <script type="text/javascript" charset="utf-8">
       $('#item_<%= item.id %>').toggle(
          function() {
            $(this).addClass('h');
            $('#events_<%= item.id %>').show('slow');
          },
          function() {
            $(this).removeClass('h');
            $('#events_<%= item.id %>').hide();
          }
        );
      </script>
      <% end %>
      <% if @install.install_items.empty? %>
      <tr>
        <td class='c' colspan='9'>
          无记录
        </td>
      </tr>
      <% end %>
    </table>
  </div>
</div>        